package ch07;

class _17_PolyArgumentTest {
	public static void main(String args[]) {
		Buyer b = new Buyer();
		Tv17 tv = new Tv17();
		Computer com = new Computer();

		b.buy(tv);
		b.buy(com);

		System.out.println("remain money: " + b.money);
		System.out.println("bonus point: " + b.bonusPoint);
	}
}

class Product {
	int price;
	int bonusPoint;

	Product(int price) {
		this.price = price;
		bonusPoint = (int) (price / 10.0);
	}
}

class Tv17 extends Product {
	Tv17() {
		super(100);
	}

	public String toString() {
		return "Tv";
	}
}

class Computer extends Product {
	Computer() {
		super(200);
	}

	public String toString() {
		return "Computer";
	}
}

class Buyer {
	int money = 1000;
	int bonusPoint = 0;

	void buy(Product p) {
		if (money < p.price) {
			System.out.println("money is scarce.");
			return;
		}

		money -= p.price;
		bonusPoint += p.bonusPoint;
		System.out.println("buy " + p);
	}
}
/*
buy Tv
buy Computer
remain money: 700
bonus point: 30
*/

